var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(e, t) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(e, t) {
        e.__proto__ = t;
    } || function(e, t) {
        for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
    })(e, t);
}, function(e, t) {
    function n() {
        this.constructor = e;
    }
    o(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype, 
    new n());
}), a = this && this.__decorate || function(e, t, o, n) {
    var i, s = arguments.length, r = s < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, o) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n); else for (var a = e.length - 1; 0 <= a; a--) (i = e[a]) && (r = (s < 3 ? i(r) : 3 < s ? i(t, o, r) : i(t, o)) || r);
    return 3 < s && r && Object.defineProperty(t, o, r), r;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("Global"), s = e("HpView"), c = e("AudioManager"), l = e("PersonView"), d = e("SkinView"), u = e("SkinItemView"), p = e("MyProfitScrollView"), h = e("PersonModel"), f = e("GameData"), g = e("EggsManager"), m = e("DataManager"), y = e("UIManager"), v = e("WebManager"), w = cc._decorator, b = w.ccclass, P = w.property, I = function(t) {
    function e() {
        var e = null !== t && t.apply(this, arguments) || this;
        return e.useBtn = null, e.personView = null, e.freeLabel = null, e.atkLabel = null, 
        e.speLabel = null, e.ranLabel = null, e.criLabel = null, e.movLabel = null, e.numLabel = null, 
        e.up = null, e.down = null, e.hpView = null, e.value = new d.SkinItemValue(), e.nums = [], 
        e.ups = [], e.downs = [], e.numPool = new cc.NodePool(), e.upPool = new cc.NodePool(), 
        e.downPool = new cc.NodePool(), e.idx = 0, e;
    }
    return i(e, t), e.prototype.onLoad = function() {
        t.prototype.onLoad.call(this);
        var e = r.G.eggPersonModelList.filter(function(e) {
            return g.default.getInstance().eggPDataMap.has(e.id);
        });
        f.GD.personIdx < 0 ? this.idx = r.G.getEggIdx(f.GD.personIdx, 2) : 0 < e.length ? this.idx = e[0].id : 0 < r.G.eggPersonModelList.length ? this.idx = r.G.eggPersonModelList[r.G.eggPersonModelList.length - 1].id : this.idx = 0, 
        this.refresh(this.idx);
    }, e.prototype.onEnable = function() {
        t.prototype.onEnable.call(this), this.show(this.idx);
    }, e.prototype.onDisable = function() {
        t.prototype.onDisable.call(this), this.removeAll();
    }, e.prototype.onClickUse = function(e) {
        c.default.getInstance().playAudio("按钮2"), v.default.getInstance().sentLog("点击隐藏皮肤界面再用一次按键"), 
        this.callback(e);
    }, e.prototype.callback = function() {
        isNaN(this.idx) || (cc.log("doUse", this.idx), r.G.tryPersonIdx = -1, f.GD.personIdx = -this.idx - 1, 
        g.default.getInstance().updateEggPerson(this.idx), m.default.getInstance().save(), 
        y.default.getInstance().loadPopPnl("egg_reward", {
            type: r.RewardType.SKIN,
            idx: this.idx
        }), this.refresh(this.idx), this.removeAll(), this.delayBtn());
    }, e.prototype.onToggle = function(e) {
        e = e.getComponent(u.default).data.rank;
        this.show(e);
    }, e.prototype.refresh = function(e) {
        this.idx = e, this.refreshBtn(e), this.refreshSkin(e), this.setValue(this.getValue(f.GD.gunIdx, e)), 
        this.refreshLabel();
    }, e.prototype.show = function(e) {
        this.idx = e, this.refreshBtn(e), this.refreshSkin(e), this.removeAll(), this.showLabel(this.getValue(f.GD.gunIdx, e));
    }, e.prototype.setValue = function(e) {
        this.value = e;
    }, e.prototype.getValue = function(e, t) {
        var o = r.G.getGunModel(e), n = r.G.eggPersonModelList.filter(function(e) {
            return e.id == t;
        }), i = 0 < n.length ? n[0] : new h.default(), s = o.ATK + i.ATK, a = 10 * Math.floor(10 / (o.IDLE + i.IDLE)), l = o.RAN, e = o.CRI + i.CRI, n = o.SPE + i.SPE, i = o.HP + i.HP;
        return new d.SkinItemValue(s, a, l, e, n, i);
    }, e.prototype.refreshLabel = function(e) {
        void 0 === e && (e = this.value), this.atkLabel.string = e.atk.toString(), this.speLabel.string = e.spe.toString(), 
        this.ranLabel.string = e.ran.toString(), this.criLabel.string = e.cri + "%", this.movLabel.string = e.mov.toString(), 
        this.hpView.init(e.hp);
    }, e.prototype.showLabel = function(e) {
        void 0 === e && (e = this.value), this.refreshLabel(e), e.atk != this.value.atk && this.append(e.atk - this.value.atk, this.atkLabel.node.parent), 
        e.spe != this.value.spe && this.append(e.spe - this.value.spe, this.speLabel.node.parent), 
        e.ran != this.value.ran && this.append(e.ran - this.value.ran, this.ranLabel.node.parent), 
        e.cri != this.value.cri && this.append(e.cri - this.value.cri, this.criLabel.node.parent), 
        e.mov != this.value.mov && this.append(e.mov - this.value.mov, this.movLabel.node.parent);
    }, e.prototype.refreshBtn = function(e) {
        e = g.default.getInstance().checkEggPerson(e);
        0 < e ? (this.myButton.node.active = !1, this.useBtn.node.active = !0, this.freeLabel.node.parent.active = !0, 
        this.freeLabel.string = "今日免费使用次数：" + e) : (this.myButton.node.active = !0, this.useBtn.node.active = !1, 
        this.freeLabel.node.parent.active = !0, this.freeLabel.string = "今日免费使用次数：0");
    }, e.prototype.refreshSkin = function(e) {
        var t = this;
        this.personView.personIdx != -1 - e && (this.personView.personIdx = -1 - e, this.personView.loadEggPerson(e).then(function() {
            t.personView.changeGun(f.GD.gunIdx), t.personView.doEquip(t.personView.personIdx, f.GD.backEquipIdx, f.GD.headEquipIdx);
        }));
    }, e.prototype.append = function(e, t) {
        var o, n = this.getNum();
        n.parent = t, n.setPosition(cc.v2(200, 0)), this.nums.push(n), 0 < e ? (n.color = cc.Color.GREEN, 
        n.getComponent(cc.Label).string = "+" + e, (o = this.getUp()).parent = t, o.setPosition(cc.v2(250, 0)), 
        this.ups.push(o)) : (n.color = cc.Color.RED, n.getComponent(cc.Label).string = "" + e, 
        (e = this.getDown()).setPosition(cc.v2(250, 0)), e.parent = t, this.downs.push(e));
    }, e.prototype.removeAll = function() {
        for (;0 < this.nums.length; ) this.numPool.put(this.nums.pop());
        for (;0 < this.ups.length; ) this.upPool.put(this.ups.pop());
        for (;0 < this.downs.length; ) this.downPool.put(this.downs.pop());
    }, e.prototype.getNum = function() {
        return 0 < this.numPool.size() ? this.numPool.get() : cc.instantiate(this.numLabel.node);
    }, e.prototype.getUp = function() {
        return 0 < this.upPool.size() ? this.upPool.get() : cc.instantiate(this.up);
    }, e.prototype.getDown = function() {
        return 0 < this.downPool.size() ? this.downPool.get() : cc.instantiate(this.down);
    }, a([ P(cc.Button) ], e.prototype, "useBtn", void 0), a([ P(l.default) ], e.prototype, "personView", void 0), 
    a([ P(cc.Label) ], e.prototype, "freeLabel", void 0), a([ P(cc.Label) ], e.prototype, "atkLabel", void 0), 
    a([ P(cc.Label) ], e.prototype, "speLabel", void 0), a([ P(cc.Label) ], e.prototype, "ranLabel", void 0), 
    a([ P(cc.Label) ], e.prototype, "criLabel", void 0), a([ P(cc.Label) ], e.prototype, "movLabel", void 0), 
    a([ P(cc.Label) ], e.prototype, "numLabel", void 0), a([ P(cc.Node) ], e.prototype, "up", void 0), 
    a([ P(cc.Node) ], e.prototype, "down", void 0), a([ P(s.default) ], e.prototype, "hpView", void 0), 
    a([ b ], e);
}(p.default);

n.default = I;